package array

func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {

	totalLength := len(nums1) + len(nums2)
	end := totalLength/2 + 1

	temp := []int{}
	for len(temp) < end {
		if len(nums1) == 0 {
			temp = append(temp, nums2[0])
			nums2 = nums2[1:]
			continue
		}
		if len(nums2) == 0 {
			temp = append(temp, nums1[0])
			nums1 = nums1[1:]
			continue
		}
		if nums1[0] < nums2[0] {
			temp = append(temp, nums1[0])
			nums1 = nums1[1:]
			continue
		} else {
			temp = append(temp, nums2[0])
			nums2 = nums2[1:]
			continue
		}
	}

	if totalLength%2 == 1 {
		return float64(temp[len(temp)-1])
	}

	return (float64(temp[len(temp)-1]) + float64(temp[len(temp)-2])) / 2

}
